package com.isoft.systemprovidor.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isoft.systemprovidor.dao.MyMessageDao;
import com.isoft.systemprovidor.entity.MyApproval;
import com.isoft.systemprovidor.entity.MyMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MyMessageService {
    @Autowired
    MyMessageDao myMessageDao;
    /*分页获取分页我的消息数据*/
    public Page<MyMessage> getallMyMessagePage(Integer currentPage , Integer size , String sysuserid){
        // 检查 sysuserid 是否为空
        if (sysuserid == null || sysuserid.isEmpty()) {
            throw new IllegalArgumentException("sysuserid 不能为空");
        }
        Page<MyMessage> myMessagePage= new Page<>();
        // 初始化分页参数
        if (currentPage == null){
            currentPage = 1;
        }
        if (size == null){
            size =10;
        }

        // 构建查询条件
        myMessagePage.setCurrent(currentPage).setSize(size);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("sysuserid",sysuserid);
        return myMessageDao.selectPage(myMessagePage,wrapper);
    }

    /*查询我的消息的未读*/
    public Integer UnreadNum(String sysuserid){
        // 检查 sysuserid 是否为空
        if (sysuserid == null || sysuserid.isEmpty()) {
            throw new IllegalArgumentException("sysuserid 不能为空");
        }
        return myMessageDao.UnreadNum(sysuserid);
    }
}
